package com.davidlife.controller;

import com.davidlife.ExceptionHandle.SysException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/")
public class TestException {
    @RequestMapping("testException")
    public String testException() throws Exception{
        System.out.println("testException执行了...");
        // 模拟异常
        try {
            int a = 10 / 0;
        } catch (Exception e) {
            //这里可保留，打印异常信息到控制台
            e.printStackTrace();
            //抛出自定义异常信息
            throw new SysException("查询所有用户出现错误了...");
        }
        return "success";
    }
}
